package demo.zyy.com.dreamstudio.fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.FrameLayout;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import demo.zyy.com.dreamstudio.R;
import demo.zyy.com.dreamstudio.base.BaseFragment;

/**
 * Created by Administrator on 2017/8/15.
 */

public class CarFragment extends BaseFragment {
    @BindView(R.id.carfragment_textswitcher)
    TextSwitcher carfragmentTextswitcher;
    private TimeCount time;
    int count;

    @Override
    protected int loadXML() {
        return R.layout.zy_carfragment_layout;
    }

    @Override
    protected void initView(View view) {

//        carfragmentTextswitcher= (TextSwitcher) view.findViewById(R.id.carfragment_textswitcher);



    }

    @Override
    protected void initData() {
        time = new TimeCount(10000000, 1000);
        if(carfragmentTextswitcher!=null){
            carfragmentTextswitcher.setInAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.textswitcher_in));
            carfragmentTextswitcher.setOutAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.textswitcher_out));
            time.start();
            carfragmentTextswitcher.setFactory(new ViewSwitcher.ViewFactory() {
                @Override
                public View makeView() {
                    TextView textView = new TextView(getActivity());
                    textView.setTextColor(Color.RED);
                    textView.setTextSize(40);
                    textView.setLayoutParams(new TextSwitcher.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
                    return textView;
                }
            });
        }else {
            Log.i("ssssssssssss","carfragment是null");
        }

    }

    @Override
    protected void initListener() {

    }

    @Override
    public void widgetClick(View v) {

    }
    class TimeCount extends CountDownTimer {
        /**
         * @param millisInFuture    The number of millis in the future from the call
         *                          to {@link #start()} until the countdown is done and {@link #onFinish()}
         *                          is called.
         * @param countDownInterval The interval along the way to receive
         *                          {@link #onTick(long)} callbacks.
         */
        public TimeCount(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }

        @Override
        public void onTick(long millisUntilFinished) {
            count = (int) (millisUntilFinished / 1000);
            carfragmentTextswitcher.setText(String.valueOf(count));
        }

        @Override
        public void onFinish() {
            carfragmentTextswitcher.setText("dead");
        }
    }


}
